package com.edu.study.controller;

import com.edu.study.entities.po.AppSysNotice;
import com.edu.study.service.AppSysNoticeService;
import com.edu.utils.UserContextUtil;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.model.AppLoginUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "10、APP通知公告")
@RestController
@RequestMapping("/api/appSysNotice")
public class AppSysNoticeController {

  @Autowired
  private AppSysNoticeService appSysNoticeService;

  @GetMapping(value = "/list")
  @ApiOperation(value = "获取APP端通知公告", response = AppSysNotice.class, responseContainer = "List")
  public AjaxResult getAppUserNotice() {
    AppLoginUser user = UserContextUtil.currentUser();

    List<AppSysNotice> noticeList = appSysNoticeService.lambdaQuery()
        .eq(AppSysNotice::getStatus, "0")
        .ge(!ObjectUtils.isEmpty(user.getCreateTime()), AppSysNotice::getCreateTime, user.getCreateTime())
        .and(
            wrapper -> wrapper
                .eq(AppSysNotice::getMassText, "0")
                .or()
                .eq(!ObjectUtils.isEmpty(user), AppSysNotice::getMemberId, user.getId()))
        .orderByDesc(AppSysNotice::getCreateTime)
        .list();

    return AjaxResult.success(noticeList);
  }
}
